<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="冷库" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
              <j-dict-select-tag type="list" v-model="queryParam.storehouse" :trigger-change="true" dictCode="flower_storehouse,name,code" placeholder="请选择冷库"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="产品">
              <a-select v-model='queryParam.variety' placeholder="请选择产品"  >
                <a-select-option v-for="(d,i) in varietyList"  :key="d.title" :value="d.text">{{ d.value }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label='打包规格'>
                <a-select   v-model='queryParam.packingSpecifications' placeholder="请选择打包规格"  >
                  <a-select-option v-for="(d,i) in psfList"  :key="d.title" :value="d.text">{{ d.value }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label='单位'>
                <a-select v-model='queryParam.flowerPoleLength' placeholder="请选择单位"  >
                  <a-select-option v-for="(d,i) in lengthList"  :key="d.id" :value="d.title">{{ d.title }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
              <a @click='handleToggleSearch' style='margin-left: 8px'>
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction } from '../../api/manage'
  import { ajaxGetDictItems} from '@/api/api'

  export default {
    name: "FlowerTagpreList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
    },
    props: ['flowerLoseId'],
    data () {
      return {
        description: '预出库台账管理页面',
        // 表头
        columns: [
          {
            title:'冷库',
            align:"center",
            dataIndex: 'storehouse_dictText',
            ellipsis: true
          },
          {
            title:'基地',
            align:"center",
            dataIndex: 'sourceBase',
            ellipsis: true
          },
          {
            title:'地块',
            align:"center",
            dataIndex: 'sourceGreenhouse',
            ellipsis: true
          },
          {
            title:'采收产品',
            align:"center",
            dataIndex: 'variety',
            ellipsis: true
          },
          {
            title:'打包规格',
            align:"center",
            dataIndex: 'packingSpecifications',
            ellipsis: true
          },
          {
            title:'等级',
            align:"center",
            dataIndex: 'classes',
            ellipsis: true
          },
          {
            title:'单位',
            align:"center",
            dataIndex: 'flowerPoleLength',
            ellipsis: true
          },
          {
            title:'分拣员',
            align:"center",
            dataIndex: 'sorter',
            ellipsis: true
          },
          {
            title:'分拣日期',
            align:"center",
            dataIndex: 'sortTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'state',
            customRender:function (text) {
              if(text === 1){
                return '预出库'
              }
              if(text === 2){
                return '已出库'
              }
              if(text === 3){
                return '损耗'
              }
              if(text === 9){
                return '已删除'
              }
            }
          },
          {
            title:'出库时间',
            align:"center",
            dataIndex: 'stockInTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            },
            ellipsis: true
          },
          {
            title:'入库时间',
            align:"center",
            dataIndex: 'stockOutTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            },
            ellipsis: true
          },
          {
            title:'入库人',
            align:"center",
            dataIndex: 'stockInUser',
            ellipsis: true
          },
          {
            title:'出库人',
            align:"center",
            dataIndex: 'stockOutUser',
            ellipsis: true
          },

        ],
        url: {
          list: "/flower/flowerLoseInfo/getFlowerTagPre",
          getFlowerTypeUrl: "/flower/flowerVariety/getFlowerType",
          getPackingSpecificationsUrl: "/flower/flowerVariety/getPackingSpecifications"
        },
        dictOptions:{},
        queryParam:{
          'flowerLoseId':this.flowerLoseId
        },
        psfList: [], //打包规格
        lengthList: [], //长度信息
        varietyList: [],
      }
    },
    computed: {

    },
    created(){
      this.initpsfDict()//初始化打包规格
      this.initlengthDict()//长度规格
      this.initVarietyDict()//鲜花产品
    },
    methods: {
      initDictConfig(){
      },
      searchReset() {
        this.queryParam = {'flowerLoseId':this.flowerLoseId}
        this.loadData(1);
      },
      //初始化打包规格信息
      initpsfDict() {
        getAction(this.url.getPackingSpecificationsUrl).then((res) => {
          if (res.success) {
            this.psfList = res.result
          }else{
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      }, //
      initlengthDict() {
        const dictCode = 'planting_flower_pole'
        ajaxGetDictItems(dictCode, null).then((res) => {
          if (res.success) {
            this.lengthList = res.result
          }
        })
      },
      initVarietyDict(){
        getAction(this.url.getFlowerTypeUrl).then((res) => {
          if (res.success) {
            this.varietyList = res.result
          }else{
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>